package cn.scu.ne04jdemo;

import java.io.File;

public class test {

    static int mnum = 0;
    static int vnum = 0;

    public static void main(String[] args) {

        //文件路径
        String path = "E:\\workspace\\vision-core";

        //调用方法
        query(new File(path));

        //输出num(符合文件的个数)
        System.out.println("method个数：" + mnum);
        System.out.println("fields个数：" + vnum);
    }


    public static void query(File queryFile) {

        //如果是一个目录
        if (queryFile.isDirectory()) {
            //把里面的文件放到数组中，方便遍历
            File[] files = queryFile.listFiles();

            for (File fs : files) {
                if (fs.isDirectory()) query(fs);
                if (fs.isFile() && fs.getName().endsWith(".java")) {
                    System.out.println("---------：" + fs.getAbsolutePath());
                    String cz = fs.getAbsolutePath().replace("E:\\workspace\\vision-core\\common\\", "")
                            .replace("E:\\workspace\\vision-core\\chainstorage\\", "")
                            .replace("E:\\workspace\\vision-core\\config\\", "")
                            .replace("E:\\workspace\\vision-core\\consensus\\", "")
                            .replace("E:\\workspace\\vision-core\\crypto\\", "")
                            .replace("E:\\workspace\\vision-core\\demo\\", "")
                            .replace("E:\\workspace\\vision-core\\executor\\", "")
                            .replace("E:\\workspace\\vision-core\\framework\\", "")
                            .replace("E:\\workspace\\vision-core\\demo\\", "")
                            .replace("src\\main\\java\\", "")
                            .replace('\\', '.').replace(".java", "");
                    try {
                        Class clz = Class.forName(cz);
                        mnum += clz.getMethods().length;
                        vnum += clz.getFields().length;
                    } catch (ClassNotFoundException e) {
                        e.printStackTrace();
                    }
                }
            }

        }
    }
}
